<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../link/heat.jsp" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/addBook.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath }/static/js/ajaxfileupload.js"></script>
</head>
<body>
<!--取出上一个页面上带来的page的值-->
<script type="text/javascript">
    //图片上传功能
    function fileChange() {//注意：此处不能使用jQuery中的change事件，因此仅触发一次，因此使用标签的：onchange属性
        // alert("change");
        $.ajaxFileUpload({
            url: '${pageContext.request.contextPath}/user/ajaxImg.action',//用于文件上传的服务器端请求地址
            secureuri: false,//是否需要安全协议:一般设置为false
            fileElementId: 'exampleInputFile',//文件上传控件的id属性  <input type="file" id="pimage" name="pimage" />
            dataType: 'json',//返回值类型 一般设置为json
            success: function (obj) //服务器成功响应处理函数
            {
                // alert(obj);
                //图片介绍那个div <div id="imgDiv" />
                $("#imgDiv").empty();  //清空原有数据
                //创建img 标签对象
                var imgObj = $("<img>");
                //给img标签对象追加属性, obj.imgurl 就是请求成功返回的 ajax对象的文件路径
                imgObj.attr("src", "/imgs/user/" + obj.imgurl);
                imgObj.attr("width", "100px");
                imgObj.attr("height", "100px");
                //将图片img标签追加到imgDiv末尾,在 id为imgDiv中显示
                $("#imgDiv").append(imgObj);
                //将图片的名称（从服务端返回的JSON中取得）赋值给文件本框
                //$("#imgName").html(data.imgName);
            },
            error: function (e)//服务器响应失败处理函数
            {
                // alert(e.message);
            }
        });
    }

    function pwdChange() {
        let pwd = $("#pwd");
        pwd.val("true");
        let input = $("input[name=userPwd]");
        alert("新密码: " + input.val())
    }
</script>
<div id="addAll">
    <div id="nav">
        <p>用户编辑</p>
    </div>
    <%-- String carLogo;String carNumber;carTime;carZuo;carColor; carPrice; carPhoto; carStatus;--%>
    <div id="table">
        <form action="${pageContext.request.contextPath}/user/update.action"
              method="post" id="myform">
            <input type="hidden" value="${requestScope.user.userId}" name="userId">
            <input type="hidden" value="false" name="pwdIsChange" id="pwd">
            <table>

                <tr>
                    <td class="one">用户名字</td>
                    <td><input type="text" name="userName" class="two" value="${requestScope.user.userName}"></td>
                </tr>
                <!--错误提示-->
                <tr class="three">
                    <td class="four"></td>
                    <td><span id="pcontenterr"></span></td>
                </tr>
                <tr>
                    <td class="one">用户性别</td>
                    <td>
                        <c:if test="${requestScope.user.userSex=='男'}">
                            男<input type="radio" name="userSex" value="男" checked="checked">&nbsp;&nbsp;&nbsp;&nbsp;
                            女<input type="radio" name="userSex" value="女">
                        </c:if>
                        <c:if test="${requestScope.user.userSex=='女'}">
                            男<input type="radio" name="userSex" value="男" >&nbsp;&nbsp;&nbsp;&nbsp;
                            女<input type="radio" name="userSex" value="女" checked="checked">
                        </c:if>
                    </td>
                </tr>
                <!--错误提示-->
                <tr class="three">
                    <td class="four"></td>
                    <td><span id="priceerr"></span></td>
                </tr>
                <tr>
                    <td class="one">用户密码</td>
                    <td><input type="text" name="userPwd" class="two" value="${requestScope.user.userPwd}"
                               onchange="pwdChange()">
                    </td>
                </tr>
                <tr>
                    <td class="one">用户手机</td>
                    <td><input type="text" name="userPhone" class="two" value="${requestScope.user.userPhone}"></td>
                </tr>
                <tr>
                <tr>
                    <td class="three">用户图片</td>
                    <td><br>
                        <div id="imgDiv" style="display:block; width: 40px; height: 50px;">
                            <img src="${requestScope.user.userPhoto}" width="100px" height="100px">
                        </div>
                        <br><br><br><br>
                        <%--<input type="file" id="pimage" name="pimage" onchange="fileChange()">--%>
                        <input type="file" id="exampleInputFile" name="userPhoto"
                               value="${requestScope.user.userPhoto}" onchange="fileChange()">
                        <span id="imgName"></span><br>
                    </td>
                </tr>
                <tr class="three">
                    <td class="four"></td>
                    <td><span></span></td>
                </tr>
                <tr>
                    <td class="one">用户部门编号</td>
                    <td>
                        <input type="text" name="departmentId" value="${requestScope.user.departmentId}">
                    </td>
                </tr>
                <!--错误提示-->
                <tr class="three">
                    <td class="four"></td>
                    <td><span></span></td>
                </tr>

                <tr>
                    <td>
                        <input type="submit" value="提交" class="btn btn-success">
                    </td>
                    <td>
                        <input type="reset" value="取消" class="btn btn-default" onclick="myclose()">
                        <script type="text/javascript">
                            function myclose() {
                                window.history.go(-1)
                            }
                        </script>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>
<script>
    $.ready(function () {
        let photo = $("input[name=userPhoto]");
        photo.attr("value", "${requestScope.user.userPhoto}")
    })
</script>
</body>
</html>
